<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <title>采购列表</title>
    <script src="/static/common/js/jquery-1.11.1.min.js" type="text/javascript"></script>
    <link rel="stylesheet" href="/static/admin/layui/css/layui.css" media="all">
</head>
<body>
<div style="margin: 65px;"></div>
<div class="demoTable" style="position: fixed;right: 40px;top:20px;">
    <button id="add" class="layui-btn" data-type="addForm" style="position: fixed;left: 40px;top:30px;"> 新增</button>
    <button id="delLog" class="layui-btn layui-btn-warm" data-type="getCheckData" style="position: fixed;left: 100px;top:30px;">导出</button>
    单据编号：
    <div class="layui-inline">
        <input class="layui-input" name="id" id="demoReload" autocomplete="off">
    </div>
    <button class="layui-btn" data-type="reload">搜索</button>
</div>
<table id="autSysLog" lay-filter="test"></table>

<script src="/static/admin/layui/layui.js"></script>
<script type="text/javascript" src="/static/common/js/dateFormat.js"></script>
<script>
    layui.use('table', function(){
        var table = layui.table;

        //第一个实例
        table.render({
            elem: '#autSysLog'
            ,height: 500
            ,url: '/purchase/selectAll' //数据接口
            ,page: true //开启分页
            ,cols: [[ //表头
                {type:'checkbox'}
                ,{field: 'id', title: '单据编号', width:120, align:'center'}
                ,{title: '供应商', minWidth:120, align:'center',templet:'#parseSupplier'}
                ,{field: 'purchasetime', title: '采购时间',sort: true, minWidth:130,align:'center',templet: '#timeFormat'}
                ,{field: 'summoney', title: '采购金额',sort: true, width:110,align:'center'}
                ,{field: 'favorable', title: '优惠金额',sort: true, minWidth:110,align:'center'}
                ,{field: 'payamount', title: '已付金额', minWidth: 110, sort: true,align:'center'}
                ,{title: '未付金额', minWidth: 110, sort: true,align:'center',templet:'#unPay'}
                ,{field: 'grade', title: '价格等级', minWidth:80,align:'center',templet:'#priceGrade'}
                ,{field: 'status', title: '审核状态', minWidth:80, align:'center',templet:'#verifyStatus'}
                ,{title: '操作', width: 200, templet: '#operator', align:'center'}
            ]]
            ,id:'testReload'
        });

        var $ = layui.$, active = {
            reload: function(){
                var demoReload = $('#demoReload');

                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        //key: {
                        id: demoReload.val()
                        //}
                    }
                });
            },
            addForm:function () {
                layer.open({
                    type: 2,
                    title: ['新增采购单','font-size:13px;margin-top:5px;'],
                    content:"/purchase/toForm",//con是Ajax返回的页面
                    btn: ['保存', '取消'],
                    area: ['1000px', '600px'],
                    shade :false,
                    maxmin :true,
                    anim: 2,
                    yes: function(index,layero) {
                        $("#form").length;//直接获取表单长度=0
                        $(layero).find("#form").length;//表单长度还是等于0
                    }
                });
            },
            getCheckData: function(){ //获取选中数据
                var checkStatus = table.checkStatus('testReload')
                        ,data = checkStatus.data;
                if(data.length>0){
                    layer.confirm('确认删除该行数据？', function(index){
                        var list=JSON.stringify(data);
                        $.post('/gis/log/delLogList',{param:list},function(result) {
                            if(result.resultStat=="SUCCESS"){
                                table.reload('testReload');
                            }else{
                                layer.alert(result.mess);
                            }
                        })
                        layer.close(index);
                    })
                }else{
                    layer.alert("ERROR: 请选择删除行");
                }

            }
        };

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        /*$('#delLog').on('click',function (obj) {debugger
            layer.confirm('真的删除行么', function(index){
                obj.getCheckData();
                layer.close(index);
            });
        })*/
    });
    function formatLevelType(type){
        if(type==10000){
            return "debug";
        }else if(type==20000){
            return "info";
        }else if(type==30000){
            return "warn";
        }else if(type==40000){
            return "error";
        }
    }


</script>
<script type="text/html" id="timeFormat">
    {{ dateFormat1(d.purchasetime) }}
</script>
<script type="text/html" id="levelType">
    {{ formatLevelType(d.logLevel)}}
</script>
<script type="text/html" id="priceGrade">
    {{#  if(d.grade ===2){ }}
    记忆价
    {{#  } else { }}
    默认价
    {{#  } }}
</script>
<script type="text/html" id="verifyStatus">
    {{#  if(d.status ===1){ }}
    已审核
    {{#  } else { }}
    未审核
    {{#  } }}
</script>
<script type="text/html" id="operator">
    {{#  if(d.status ===1){ }}
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    {{#  } else { }}
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="verify">审核</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    {{#  } }}
</script>

<script type="text/html" id="unPay">
    {{d.summoney-d.favorable-d.payamount}}
</script>
<script type="text/html" id="parseSupplier">
    {{#  if(d.supplier!=null){ }}
    {{d.supplier.name}}
    {{#  } else { }}
    无数据
    {{#  } }}
</script>

</body>
</html>
